package com.weixin.paleituo.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.weixin.paleituo.R;
import com.weixin.paleituo.adapter.CustomGoodsListPreRecycleAdapter;
import com.weixin.paleituo.adapter.GoodsListPreRecycleAdapter;
import com.weixin.paleituo.annotation.OrderCreatedType;
import com.weixin.paleituo.base.BasePersonActivity;
import com.weixin.paleituo.bean.OrderGoods;
import com.weixin.paleituo.contans.Contans;
import com.weixin.paleituo.util.UIUtils;
import com.weixin.paleituo.view.LoadingPagerHead;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * 商品清单展示
 * 这个界面只是展示订单所有商品的清单信息，不提供任何事件交互
 *
 * @author fengzhen
 * @version v1.0, 2018/4/1
 */
public class GoodsListPreActivity extends BasePersonActivity {

    @BindView(R.id.recycle_activity_goods_list_pre)
    RecyclerView mRecycleActivityGoodsListPre;

    public static Intent call2GoodsListPreActivity(Context context, ArrayList<OrderGoods> goods) {
        Intent intent = new Intent(context, GoodsListPreActivity.class);
        intent.putExtra(Contans.INTENT_DATA, goods);
        return intent;
    }

    public static Intent call2GoodsListPreActivity(Context context, ArrayList<OrderGoods> goods, int type) {
        Intent intent = new Intent(context, GoodsListPreActivity.class);
        intent.putExtra(Contans.INTENT_DATA, goods);
        intent.putExtra(Contans.INTENT_TYPE, type);
        return intent;
    }

    private ArrayList<OrderGoods> mGoodsList;
    private int mType;

    @Override
    protected View getContentView(Context context) {
        return UIUtils.inflate(R.layout.activity_goods_list_pre);
    }

    @Override
    protected void initData() {
        super.initData();

        mTvTitle.setText("商品清单");
        mGoodsList = (ArrayList<OrderGoods>) getIntent().getSerializableExtra(Contans.INTENT_DATA);
        mType = getIntent().getIntExtra(Contans.INTENT_TYPE, 0);

        int goodsCount = 0;
        for (OrderGoods goods :
                mGoodsList) {
            goodsCount += goods.getCount();
        }
        mTvSmalTitle.setText(String.format(getString(R.string.string_count_goods), goodsCount));
        mTvSmalTitle.setTextColor(ContextCompat.getColor(this, R.color.c_ff999999));
        mTvSmalTitle.setVisibility(View.VISIBLE);

        if (mType != OrderCreatedType.SHARED) {
            mRecycleActivityGoodsListPre.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
            GoodsListPreRecycleAdapter goodsListPreAdapter = new GoodsListPreRecycleAdapter(this, mGoodsList);
            mRecycleActivityGoodsListPre.setAdapter(goodsListPreAdapter);
        } else {
            mRecycleActivityGoodsListPre.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
            CustomGoodsListPreRecycleAdapter customGoodsListPreAdapter = new CustomGoodsListPreRecycleAdapter(this, mGoodsList);
            mRecycleActivityGoodsListPre.setAdapter(customGoodsListPreAdapter);
        }
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        setResult(RESULT_CANCELED);
        finish();
    }
}
